package cc.momas.momall.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import cc.momas.common.vo.EasyUIDataGridResult;
import cc.momas.momall.mapper.TbItemParamMapper;
import cc.momas.momall.po.TbItemParam;
import cc.momas.momall.po.TbItemParamExample;
import cc.momas.momall.service.IItemParamService;

@Service("itemParamService")
public class ItemParamServiceImpl implements IItemParamService {

	@Autowired
	private TbItemParamMapper itemParamMapper;

	@Override
	public EasyUIDataGridResult getItemParam(Integer page, Integer rows) {
		// 设置分页信息
		PageHelper.startPage(page, rows);
		// 设置查询条件(此处为空)
		TbItemParamExample example = new TbItemParamExample();
		// 执行查询
		List<TbItemParam> list = itemParamMapper.selectByExampleWithBLOBs(example);
		// 获取分页结果
		PageInfo<TbItemParam> info = new PageInfo<>(list);
		// 把查询到的结果进行封装,以供返回
		EasyUIDataGridResult result = new EasyUIDataGridResult();
		result.setRows(info.getList());
		result.setTotal(info.getTotal());

		return result;
	}

	@Override
	public TbItemParam getById(Long id) {
		return itemParamMapper.selectByPrimaryKey(id);
	}

	@Override
	public List<TbItemParam> getByItemCatId(Long id) {
		TbItemParamExample example = new TbItemParamExample();
		example.createCriteria().andItemCatIdEqualTo(id);
		List<TbItemParam> list = itemParamMapper.selectByExampleWithBLOBs(example);
		return list;
	}

	@Override
	public int batchDelete(String ids) {
		int count = 0 ;
		String [] id = ids.split(",");
		for (String s : id) {
			 count += itemParamMapper.deleteByPrimaryKey(Long.valueOf(s));
		}
		return count;
	}

}
